package org.inspursc.s0517.health.evaluation.converter;


import com.alibaba.fastjson.JSON;
import org.inspursc.s0517.health.evaluation.dto.AnRadioDTO;
import org.inspursc.s0517.health.evaluation.entity.AnRadio;
import org.springframework.beans.BeanUtils;

import java.util.Arrays;


/**
 * @author B_Dream
 * @date 2018/6/20 10:19
 */
public class AnRadioConverter {

    public static AnRadio converter(AnRadioDTO anDTO) {
        AnRadio an = new AnRadio();
        BeanUtils.copyProperties(anDTO, an);
        an.setOtherOptionsAnswer(JSON.toJSONString(anDTO.getOtherOptionsAnswer()));
        StringBuilder sb=new StringBuilder();
        for(String str:anDTO.getOtherOptionsAnswer()){
            sb.append(str);
            sb.append("||");
        }
        return an;
    }

    public static AnRadioDTO converter(AnRadio an) {
        AnRadioDTO anDTO = new AnRadioDTO();
        BeanUtils.copyProperties(an, anDTO);
        //todo
//        List<String> list=JSONObject.parseArray(an.getOtherOptionsAnswer(),String.class);
        String[] str=  an.getOtherOptionsAnswer().split("\\|");
        anDTO.setOtherOptionsAnswer(Arrays.asList(str));
        return anDTO;
    }

}
